<template>
    <div>
        <div @click="preview">梦想书城</div>
        <slider :announcement="announcement" :slides="slides"></slider>
        <booklist :books="lastupdatebooks"
                  heading="最近更新"
                  @haha="preview($event) "></booklist>

        <booklist :books="recommended"
                  heading="编辑推荐"
                  @haha="preview($event)"></booklist>

        <modal-dialog ref="dialog">
            <div slot="heading"></div>
            <div>
                <div v-if="selected">
                    <h2>{{ selected.title }}</h2>
                </div>
            </div>
        </modal-dialog>
    </div>
</template>


<script type="text/ecmascript-6">
    import slider from './slider.vue'
    import booklist from "./list.vue"
    import ModalDialog from "./components/dialog.vue"
    import faker from "./fixtures/faker"



    export default{
        components: {slider, booklist,ModalDialog}//{slider, booklist}
        ,created(){
            this.$http.get('/data.json').then(res=>{
                this.announcement=res.body.announcement
                this.slides=res.body.slides
                this. lastupdatebooks=res.body. lastupdatebooks
                this.recommended=res.body.recommended
            })
        }

        ,data(){
            return {
                selected:null,
                lastupdatebooks:[{img_url:require("./fixtures/covers/1.svg"),title:'揭开数据真相',authors:['tim','liu']}
                    ,{img_url:require("./fixtures/covers/2.svg"),title:'Android高级进阶',authors:['大漠穷秋']}
                    ,{img_url:require("./fixtures/covers/3.svg"),title:'淘宝天猫运营',authors:['唐晓君','林子雨','黄振虎']}
                ],
                recommended:[{img_url:require("./fixtures/covers/4.svg"),title:'数据真相',authors:['liu']}
                    ,{img_url:require("./fixtures/covers/5.svg"),title:'高级进阶',authors:['林子雨','大漠穷秋']}
                    ,{img_url:require("./fixtures/covers/6.svg"),title:'天猫运营',authors:['唐晓君','黄振虎']}
                ]
                , announcement:'本周新书优惠,新上架电子书一律8折',
                slides: [{img_url:require('./fixtures/sliders/t1.svg')}
                    , {img_url: require('./fixtures/sliders/t2.svg')}]
            }
        }
        ,methods:{

                preview (book) {
                    this.selected = book
                    this.$refs.dialog.open()
            }
        }
    }
</script>
